﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace wpfTool
{
    /// <summary>
    /// Interaction logic for CheckBoxInput.xaml
    /// </summary>
    public partial class CheckBoxInput : UserControl, IPropertyGridItem
    {
        int id = 0;

        public CheckBoxInput()
        {
            InitializeComponent();
            
            theCheckBox.Checked += new RoutedEventHandler(updateCheckBox);
            theCheckBox.Unchecked += new RoutedEventHandler(updateCheckBox);
        }

        public bool CheckBoxValue
        {
            get { return (bool)theCheckBox.IsChecked;}
            set { theCheckBox.IsChecked = value; }
        }

        void updateCheckBox(object sender, RoutedEventArgs e)
        {
            CheckBoxValueChangedEvent(this, CheckBoxValue);
        }

        public event Window1.PropertyGridItemChangeHandler CheckBoxValueChangedEvent;

        void IPropertyGridItem.registerItemUpdateEvent(wpfTool.PropertyGrid grid)
        {
            CheckBoxValueChangedEvent += new Window1.PropertyGridItemChangeHandler(grid.OnGridItemChanged);
        }

        void IPropertyGridItem.unregisterItemUpdateEvent(wpfTool.PropertyGrid grid)
        {
            CheckBoxValueChangedEvent -= grid.OnGridItemChanged;
        }

        int IPropertyGridItem.getID()
        {
            return id;
        }

        void IPropertyGridItem.setID(int i)
        {
            if (id != 0)
            {
                throw new System.Exception("ID is not 0!");
            }

            id = i;
        }
    }
}
